package com.ev.framework.config;

import com.ev.common.jobs.CodeBindingPlanJob;
import com.ev.common.jobs.NoticeJob;
import org.quartz.CronTrigger;
import org.quartz.JobDataMap;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * @author 顾明杰
 * 定时任务配置类，目前定时任务通过保存任务进入数据库实现
 */
//@Configuration
@Deprecated
public class QuartzConfig {

    @Bean
    JobDetailFactoryBean jobDetailFactoryBean(){
        JobDetailFactoryBean bean =  new JobDetailFactoryBean();
        bean.setJobClass(NoticeJob.class);
        //可带参数的定时任务
        JobDataMap jobDataMap = new JobDataMap();
        bean.setJobDataMap(jobDataMap);
        bean.setDurability(true);
        return bean;
    }


    @Bean
    CronTriggerFactoryBean cronTriggerFactoryBean(){
        CronTriggerFactoryBean bean = new CronTriggerFactoryBean();
        bean.setJobDetail(jobDetailFactoryBean().getObject());
        bean.setCronExpression("0 50 23 * * ?");
        return bean;
    }

    @Bean
    SchedulerFactoryBean schedulerFactoryBean(){
        SchedulerFactoryBean bean = new SchedulerFactoryBean();
        CronTrigger cronTrigger = cronTriggerFactoryBean().getObject();
        bean.setTriggers(cronTrigger);
        return bean;
    }

    @Bean
    JobDetailFactoryBean jobDetailFactoryBean2(){
        JobDetailFactoryBean bean =  new JobDetailFactoryBean();
        bean.setJobClass(CodeBindingPlanJob.class);
        //可带参数的定时任务
        JobDataMap jobDataMap = new JobDataMap();
        bean.setJobDataMap(jobDataMap);
        bean.setDurability(true);
        return bean;
    }


    @Bean
    CronTriggerFactoryBean cronTriggerFactoryBean2(){
        CronTriggerFactoryBean bean = new CronTriggerFactoryBean();
        bean.setJobDetail(jobDetailFactoryBean2().getObject());
        bean.setCronExpression("0 10 23 * * ?");
        return bean;
    }

    @Bean
    SchedulerFactoryBean schedulerFactoryBean2(){
        SchedulerFactoryBean bean = new SchedulerFactoryBean();
        CronTrigger cronTrigger = cronTriggerFactoryBean2().getObject();
        bean.setTriggers(cronTrigger);
        return bean;
    }

}
